﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using JKF.DataModule.SqlServerDAL;
using JKF.Entities.Model;

namespace JKF.BusinessLayer.BLL
{
    public partial class bllCUSTOMER
    {
        #region Methords
        /// <summary>
        /// 查询顾客信息
        /// </summary>
        /// <param name="dateStart"></param>
        /// <param name="dateEnd"></param>
        /// <param name="field"></param>
        /// <param name="fieldOp"></param>
        /// <param name="fieldKey"></param>
        /// <param name="pageCurrent"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="rowCount"></param>
        /// <returns></returns>
        public DataTable GetCurstomers(string dateStart, string dateEnd, string field, string fieldOp, string fieldKey, string ownShop, string currentUser,
            int pageCurrent, int pageSize, ref int pageCount, ref int rowCount)
        {
            return dalCUSTOMER.GetCurstomerPage(dateStart, dateEnd, field, fieldOp, fieldKey, ownShop, currentUser, pageCurrent, pageSize, ref pageCount, ref rowCount);
        }

        public void DeleteCustomer(Guid customerKey)
        {
            dalCUSTOMER.DeleteCustomer(customerKey);
        }

        /// <summary>
        /// 高级查询顾客信息
        /// </summary>
        /// <param name="cardNo"></param>
        /// <param name="levelCode">逗号分割的</param>
        /// <param name="name"></param>
        /// <param name="sex"></param>
        /// <param name="refereeCard"></param>
        /// <param name="referee"></param>
        /// <param name="idCard"></param>
        /// <param name="ageFrom"></param>
        /// <param name="ageTo"></param>
        /// <param name="mobile"></param>
        /// <param name="phone"></param>
        /// <param name="groupKey">逗号分割的groupkey</param>
        /// <param name="areaCode"></param>
        /// <param name="birthdayFrom"></param>
        /// <param name="birthdayTo"></param>
        /// <param name="dateCreateStart"></param>
        /// <param name="dateCreateEnd"></param>
        /// <param name="avaPointFrom"></param>
        /// <param name="avaPointTo"></param>
        /// <param name="currentUser"></param>
        /// <param name="pageCurrent"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="rowCount"></param>
        /// <returns></returns>
        public DataTable GetCustomerAdvPage(string cardNo, string levelCode, string name,
            string sex, string refereeCard, string referee,
            string idCard, int? ageFrom, int? ageTo,
            string mobile, string phone, string groupKey,
            string areaCode, DateTime? birthdayFrom, DateTime? birthdayTo,
            DateTime? dateCreateStart, DateTime? dateCreateEnd, int? avaPointFrom, int? avaPointTo, string currentUser,
            string title, string family,
            int pageCurrent, int pageSize, ref int pageCount, ref int rowCount)
        {
            return dalCUSTOMER.GetCustomerAdvPage(cardNo, levelCode, name, sex, refereeCard, referee, idCard,
                ageFrom, ageTo, mobile, phone, groupKey, areaCode, birthdayFrom, birthdayTo,
                dateCreateStart, dateCreateEnd, avaPointFrom, avaPointTo, currentUser, title, family,
                pageCurrent, pageSize, ref  pageCount, ref  rowCount);
        }

        /// <summary>
        /// 卡号是否存在
        /// </summary>
        /// <param name="cardNo"></param>
        /// <returns></returns>
        public bool CardNoExists(string cardNo, string customerKey)
        {
            var curstomer = new dalCUSTOMER();
            return curstomer.CardNoExists(cardNo, customerKey);
        }

        /// <summary>
        /// 手机号是否存在
        /// </summary>
        /// <returns></returns>
        public bool MobileExists(string mobile, string customerKey)
        {
            var curstomer = new dalCUSTOMER();
            return curstomer.MobileExists(mobile, customerKey);
        }

        /// <summary>
        /// 查询拥有手机号的人员
        /// </summary>
        /// <param name="customerCardNo"></param>
        /// <param name="customerName"></param>
        /// <param name="dateStart"></param>
        /// <param name="dateEnd"></param>
        /// <param name="customerLevel"></param>
        /// <param name="gender"></param>
        /// <param name="ageFrom"></param>
        /// <param name="ageTo"></param>
        /// <param name="pointFrom"></param>
        /// <param name="pointTo"></param>
        /// <param name="areaCode"></param>
        /// <param name="shopCodes"></param>
        /// <param name="currentUser"></param>
        /// <param name="noMobile"></param>
        /// <returns></returns>
        public static DataTable GetCustomer4MobileSelect(string customerCardNo, string customerName, DateTime? dateStart,
                                                         DateTime? dateEnd, string customerLevel, string gender,
                                                         int? ageFrom, int? ageTo, int? pointFrom, int? pointTo,
                                                         string areaCode, string shopCodes, string currentUser,
                                                         bool noMobile, string mobileNum, string shopCode)
        {
            return dalCUSTOMER.GetCustomer4MobileSelect(customerCardNo, customerName, dateStart, dateEnd, customerLevel,
                                                        gender,
                                                        ageFrom, ageTo, pointFrom, pointTo, areaCode, shopCodes,
                                                        currentUser, noMobile, mobileNum, shopCode);
        }

        /// <summary>
        /// 通过手机号获得人员Key
        /// </summary>
        /// <returns></returns>
        public static string GetCustomerKeyByMobileNo(string mobileNo)
        {
            return dalCUSTOMER.GetCustomerKeyByMobileNo(mobileNo);
        }

        /// <summary>
        /// 获得提醒数据
        /// </summary>
        /// <param name="dateValue">多少天</param>
        /// <param name="remindType">0:customer1:lvxing2:swing</param>
        /// <param name="currentUser"></param>
        /// <param name="pageCurrent"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageCount"></param>
        /// <param name="rowCount"></param>
        /// <returns></returns>
        public static DataTable GetRemindByRemindTypePaging(int dateValue, int remindType, Guid currentUser, string productName,
                                                            int pageCurrent, int pageSize, ref int pageCount,
                                                            ref int rowCount)
        {
            return dalCUSTOMER.GetRemindByRemindTypePaging(dateValue, remindType, currentUser, productName, pageCurrent, pageSize,
                                                           ref pageCount, ref rowCount);
        }

        public string AddPhoto(string CUSTOMER_KEY, string PHOTO_URL)
        {
            dalCUSTOMER c = new dalCUSTOMER();
            return c.AddPhoto(CUSTOMER_KEY, PHOTO_URL);
        }

        public string GetPhotoUrlByKey(string customer_key)
        {
            dalCUSTOMER c = new dalCUSTOMER();
            string url= c.GetPhotoUrlByKey(customer_key);
            return GetFileName(url);
        }

        public static string GetFileName(String path)
        {
            if (string.IsNullOrEmpty(path))
                return "";

            if (path.Contains("\\"))
            {
                string[] arr = path.Split('\\');
                return "/UploadFiles/" + arr[arr.Length - 1];
            }
            else
            {
                string[] arr = path.Split('/');
                return "/UploadFiles/" + arr[arr.Length - 1];
            }
        }
        #endregion
    }
}
